package com.etc.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.etc.api.MessageSend;
import com.etc.service.SellerService;
/**
 * 短信验证Servlet控制类
 */
@WebServlet("/user.action")
public class MessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	//验证手机号是否已存在
	private SellerService ss;
	
        
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MessageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
   	 * Get请求
   	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   	 * @param request
   	 *  @param response
   	 */
   	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String op=request.getParameter("op");//判断请求方式
		//统一设置编码格式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");



		 PrintWriter out=response.getWriter();

		if("sendCode".equals(op)) {
			String phoneNumber=request.getParameter("phoneNumber");
			MessageSend ms=new MessageSend();			
			StringBuilder code= ms.sendCode(phoneNumber);
			HttpSession session=request.getSession();
			session.setAttribute("code", code);			
			System.out.println("doGet : code : sendCode :"+code);
			out.print(code);
			out.close();			
		}	
	}

    /**
   	 * Post请求
   	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   	 * @param request
   	 *  @param response
   	 */
   	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	

}
